package nccloud.web.erm.action.expenseaccount.jkbx;

import nccloud.framework.core.exception.ExceptionUtils;
import nccloud.framework.core.io.WebFile;
import nccloud.framework.core.json.IJson;
import nccloud.framework.web.action.itf.ICommonAction;
import nccloud.framework.web.container.IRequest;
import nccloud.framework.web.convert.translate.Translator;
import nccloud.framework.web.json.JsonFactory;
import nccloud.framework.web.ui.pattern.extbillcard.ExtBillCard;
import nccloud.framework.web.ui.pattern.grid.Grid;
import nccloud.web.erm.util.expenseaccount.KKExpenseaccountMainUtil;

public class ExpenseaccountImportAction
  implements ICommonAction
{
  public Object doAction(IRequest request)
  {
    WebFile[] webfiles = request.readFiles();
    Grid grid = null;
    IJson json = JsonFactory.create();
    String read = ((String[])request.readParameters().get("data"))[0];
    ExtBillCard extbillcard = (ExtBillCard)json.fromJson(read, ExtBillCard.class);
    try
    {
      grid = KKExpenseaccountMainUtil.getGrid(webfiles[0].getInputStream(), extbillcard);
      grid.setTempletid(extbillcard.getTempletid());
      grid.setPageid(extbillcard.getPageid());
      Translator translator = new Translator();
      translator.translate(grid);
      extbillcard.addBody(grid);

      KKExpenseaccountMainUtil.dealZzhllxForPrint(extbillcard);
      return extbillcard;
    } catch (Exception e) {
      ExceptionUtils.wrapException(e);
    }
    return null;
  }
}